package com.atguigu.distributed.lock.leecode.tree;

import com.atguigu.distributed.lock.leecode.TreeNode;

import java.util.ArrayList;
import java.util.List;

/**
 * 力扣中等199：二叉树的右视图
 */
public class TreeRightView {
    int dep = 0;
    public List<Integer> rightSideView(TreeNode root) {
        List<Integer> res = new ArrayList<>();
        if(root==null){
            return res;
        }
        dfs(res,root,0);
        return res;
    }
    private void dfs(List<Integer> res,TreeNode root,int depth){
        if(root==null){
            return;
        }
        depth++;
        if(depth>dep){
            res.add(root.data);
        }
        dfs(res,root.right,depth);
        dfs(res,root.left,depth);
    }
}
